package com.Test;

import com.itheima.Utils.MyBatisUtils;
import com.itheima.pojo.Customer;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import java.util.List;

public class CustomerTest {
    @Test
    public void findCustomerBYNameAndJobsTest() {
        SqlSession sqlSession = MyBatisUtils.getSession();
        Customer customer = new Customer();
        customer.setUsername("jack");
        customer.setJobs("teacher");
        List<Customer> customers = sqlSession.selectList("findCustomerBYNameAndJobs", customer);
        for (Customer cust : customers) {
            System.out.println(cust);
        }
        sqlSession.commit();
        sqlSession.close();
    }
    @Test
    public void updateCustomerBYSrtTest() {
        //37页代码
        SqlSession sqlSession = MyBatisUtils.getSession();
        Customer customer = new Customer();
        customer.setId(3);
        customer.setPhone("11111111");
        customer.setUsername("jack");
        int rows = sqlSession.update("com.itheima.mapper.CustomerMapper.updateByPrimaryKeySelective", customer);
        if (rows > 0) {
            System.out.println("成功");
        }
        else {
            System.out.println("失败");
        }
        sqlSession.commit();
        sqlSession.close();
    }

    @Test
    public void findByArrayTest() {
        SqlSession sqlSession = MyBatisUtils.getSession();
        Integer[] roleIds = new Integer[]{2,3};
        List<Customer> customers = sqlSession.
                selectList("com.mapper.CustomerMapper.findByArray", roleIds);
        for (Customer cust : customers) {
            System.out.println(cust);
        }
        sqlSession.close();
    }
}
